package sysu.el.array.ints;

import java.util.Iterator;

/**
 * OK, this array should be as simple as possible.
 * @author Edwin
 *
 */
public class ArrInt implements java.util.RandomAccess, Iterator<Integer>{
	public int counter;
	public int list[];
	
	public int[] elements(){
		return list;
	}
	
	/**
	 * Private, just for wrap()
	 */
	protected ArrInt(){
	}
	
	public static ArrInt wrap(int counter, int list[]){
		ArrInt arr = new ArrInt();
		arr.counter = counter;
		arr.list = list;
		return arr;
	}
	
	public ArrInt(int num){
		this.list = new int[num];
		this.init();
	}
	
	public void init(){
		counter = 0;
	}
	
	public void reset(){
		counter = 0;
	}
	
	public void add(int elem){
		list[counter ++] = elem;
	}
	
	public int[] toArray(){
		int[] new_list = new int[this.counter];
		System.arraycopy(this.list, 0, new_list, 0, counter);
		return new_list;
	}
	
	public void reduceSize(){
		int[] new_list = new int[this.counter];
		this.list = this.toArray();
	}
	
	public ArrInt createReducedVersion(){
		return ArrInt.buildReducedVersion(this);
	}
	
	public static ArrInt buildReducedVersion(ArrInt prev){
		int len = prev.counter;
		ArrInt cur = new ArrInt(len);
		System.arraycopy(prev, 0, cur.list, 0, len);
		cur.counter = len;
		return cur;
	}
	
	
	public void swap(int a, int b){
		int tmp = a;
		a = b;
		b = tmp;
	}
	
	public static ArrInt NULL = new ArrInt(0);
	
	public static ArrInt wrap(int[] b){
		ArrInt a = new ArrInt();
		a.list = b;
		a.counter = b.length;
		return a;
	}
	
	public static ArrInt[] wrap(int[][] b){
		ArrInt[] a = new ArrInt[b.length];
		for (int i=0; i<a.length; i++){
			a[i] = wrap(b[i]);
		}
		return a;
	}

	@Override
	public boolean hasNext() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Integer next() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub
		
	}
	
}

